package com.hemerasolutions.v2trainer.model.schedule;


import com.hemerasolutions.v2trainer.model.base.BaseModel;

//import java.text.DateFormatSymbols;
//import java.util.ArrayList;
//import java.util.Calendar;
//import java.util.Collections;
//import java.util.Date;
//import java.util.GregorianCalendar;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;


@Entity
public class CycleType extends BaseModel {

	private static final long serialVersionUID = 1L;

    @Column(length = 50)
	private String name;

    @Column(length = 180)	
	private String description;
	
    @Column
	private int periodicity;
	
    @OneToMany
    @JoinColumn(name = "cycle_id") 	
	private List<Cycle> cycles;

	
	public CycleType() {
		super();
	}

	
	public CycleType(String name, String description, List<Cycle> cycles) {
		super();
		this.name = name;
		this.description = description;
		this.cycles = cycles;
	}

	
//	
//	public CycleType(String name, String description, int year, int periodicity) {
//		super();
//		this.name = name;
//		this.description = description;
//		this.periodicity = periodicity;
//	}
//	
//	public void calcPeriodicity(List<MicroCycle> fullMicroCycles){
//
//		List<MicroCycle> micros = new ArrayList<MicroCycle>();
//		this.cycles = new ArrayList<Cycle>();
//		int count = 1;
//		int begWeek = 1;
//		int endWeek = 1;
//		
//		for(int x = 0; x < fullMicroCycles.size(); x++){
//
//			MicroCycle micro = fullMicroCycles.get(x);
//			micros.add(micro);
//
//			if(micro.getWeek() % this.periodicity == 0 ){
//				this.cycles.add(new Cycle(String.valueOf(count),begWeek,endWeek,micros));
//				micros = new ArrayList<MicroCycle>();
//				begWeek = endWeek + 1;
//				count++;	
//			}else if(x == (fullMicroCycles.size() - 1)){
//				this.cycles.add(new Cycle(String.valueOf(count),begWeek,endWeek,micros));
//			}
//			
//			endWeek = endWeek + 1;
//		}
//	}
//		
//	
//	/* Add a new cycle */
//	public void addCycle(String name, String description, int begWeek, int endWeek, List<MicroCycle> fullMicroCycles){
//
//		List<MicroCycle> micros = new ArrayList<MicroCycle>();
//
//		for(MicroCycle micro:fullMicroCycles){
//			if(micro.getWeek() >= begWeek || micro.getWeek() <= endWeek ){
//				micros.add(micro);
//			}
//		}
//		this.cycles.add(new Cycle(name,description,begWeek,endWeek,micros));
//
//		Collections.sort(this.cycles);		
//	}
//		
//	
//
//	
//	/* Start with weeks of year as cycles */
//	public static List<Cycle> weeksOfYear(int year){
//
//		GregorianCalendar base 	= new GregorianCalendar();
//		Cycle cycle;
//		MicroCycle microCycle;
//		List<Cycle> cycles = new ArrayList<Cycle>();
//		int week = 1;
//		int count = 1;
//		Date begin, end;
//		
//		base.set(Calendar.YEAR,year);
//		base.set(Calendar.WEEK_OF_YEAR, week);	
//		base.set(Calendar.DAY_OF_WEEK, base.getFirstDayOfWeek());
//
//		if(base.get(Calendar.YEAR) != year){
//			week = 2;
//			base.set(Calendar.YEAR,year);
//			base.set(Calendar.WEEK_OF_YEAR, week);	
//			base.set(Calendar.DAY_OF_WEEK, base.getFirstDayOfWeek());
//
//		}
//
//		while(base.get(Calendar.YEAR) == year){
//
//			begin = base.getTime();
//			base.add(Calendar.DAY_OF_YEAR, 6);
//			end = base.getTime();
//
//			cycle = new Cycle(String.valueOf(count),week,week,new ArrayList<MicroCycle>());
//			
//			microCycle = new MicroCycle(String.valueOf(count),begin,end,count,new ArrayList<Cycle>(),new ArrayList<DaySchedule>());
//			cycle.getMicroCycles().add(microCycle);
//
//			cycles.add(cycle);
//			
//			week = week + 1;	
//			count = count + 1;
//			
//			base.set(Calendar.WEEK_OF_YEAR, week);	
//			base.set(Calendar.DAY_OF_WEEK, base.getFirstDayOfWeek());
//		
//		}
//		
//		return cycles;
//		
//	}
//	
//	
//	/* Start with weeks of year as cycles */
//	public static List<MicroCycle> microCyclesOfYear(int year){
//
//		GregorianCalendar base 			= new GregorianCalendar();
//		GregorianCalendar auxCalendar 	= new GregorianCalendar();
//		MicroCycle microCycle;
//		List<MicroCycle> microCycles = new ArrayList<MicroCycle>();
//		int week = 1;
//		int count = 1;
//		Date begin, end, dateAux;
//		
//		base.set(Calendar.YEAR,year);
//		base.set(Calendar.WEEK_OF_YEAR, week);	
//		base.set(Calendar.DAY_OF_WEEK, base.getFirstDayOfWeek());
//
//		if(base.get(Calendar.YEAR) != year){
//			week = 2;
//			base.set(Calendar.YEAR,year);
//			base.set(Calendar.WEEK_OF_YEAR, week);	
//			base.set(Calendar.DAY_OF_WEEK, base.getFirstDayOfWeek());
//
//		}
//
//		while(base.get(Calendar.YEAR) == year){
//
//			
//			begin = base.getTime();
//			base.add(Calendar.DAY_OF_YEAR, 6);
//			end = base.getTime();
//
//			microCycle = new MicroCycle(String.valueOf(count),begin,end,count,new ArrayList<Cycle>(),new ArrayList<DaySchedule>());
//
//			dateAux = begin;
//			
//			for(int x = 1; x <=7 ;x++){
//				DaySchedule day = new DaySchedule();
//				day.setDayDate(dateAux);
//				day.setSteps(new ArrayList<Step>());
//				microCycle.getDaySchedules().add(day);
//				auxCalendar.setTime(dateAux);
//				auxCalendar.add(Calendar.DAY_OF_MONTH, 1);
//				dateAux = auxCalendar.getTime();
//
//			}
//			
//			microCycles.add(microCycle);
//			
//			week = week + 1;	
//			count = count + 1;
//
//			base.set(Calendar.WEEK_OF_YEAR, week);	
//			base.set(Calendar.DAY_OF_WEEK, base.getFirstDayOfWeek());
//			
//		}
//
//		return microCycles;
//		
//	}	
//	
//	/* Start with months of year as cycles and weeks as microcycles */
//	public static List<Cycle> monthsAndWeeksOfYear(int year){
//		GregorianCalendar base = new GregorianCalendar();
//		MicroCycle microCycle;
//		Cycle month = null;
//		int week = 1;
//		int day =0;
//		int count = 1;
//		Date begin, end;
//		List<Cycle> cycles = new ArrayList<Cycle>();
//		
//		
//		base.set(Calendar.YEAR,year);
//		base.set(Calendar.WEEK_OF_YEAR, week);	
//		base.set(Calendar.DAY_OF_WEEK, base.getFirstDayOfWeek());
//
//		if(base.get(Calendar.YEAR) != year){
//			week = 2;
//			base.set(Calendar.YEAR,year);
//			base.set(Calendar.WEEK_OF_YEAR, week);	
//			base.set(Calendar.DAY_OF_WEEK, base.getFirstDayOfWeek());
//
//		}
//
//		while(base.get(Calendar.YEAR) == year){
//
//			if( month == null || !month.getName().equals(CycleType.getMonthForInt(base.get(Calendar.MONTH))) ){
//				begin = base.getTime();
//				base.set(Calendar.DAY_OF_MONTH, base.getActualMaximum(Calendar.DAY_OF_MONTH));
//				end = base.getTime();
//				month = new Cycle(CycleType.getMonthForInt(base.get(Calendar.MONTH)),0,0,new ArrayList<MicroCycle>());
//				
//				cycles.add(month);	
//				base.set(Calendar.WEEK_OF_YEAR, week);	
//				base.set(Calendar.DAY_OF_WEEK, base.getFirstDayOfWeek());
//			}
//			
//			
//			begin = base.getTime();
//			day = base.get(Calendar.DAY_OF_MONTH);
//			base.add(Calendar.DAY_OF_YEAR, 6);
//			end = base.getTime();
//			microCycle = new MicroCycle(String.valueOf(day),begin,end,count,new ArrayList<Cycle>(),new ArrayList<DaySchedule>());
//
//			month.getSubCycles().add(microCycle);
//			week = week + 1;	
//			count = count + 1;
//
//			base.set(Calendar.WEEK_OF_YEAR, week);	
//			base.set(Calendar.DAY_OF_WEEK, base.getFirstDayOfWeek());
//
//		}
//
//		return cycles;		
//	
//	}
//	
//	public static String getMonthForInt(int num) {
//	    String month = null;
//	    DateFormatSymbols dfs = new DateFormatSymbols();
//	    String[] months = dfs.getMonths();
//	    if (num >= 0 && num <= 11 ) {
//	        month = months[num];
//	    }
//	    return month;
//	}
//
//	
//	
	
}
